package com.cskaoyan.recursion;

/*
        3. 求n的阶乘
        f(n) = n * (n - 1) * (n - 2) * ... * 1
        f(n) = n *((n -1) * (n - 2) * ... * 1)
        f(n) = n * f(n - 1)
        f(1) = 1

 */
public class Demo4Exercise {

    public static void main(String[] args) {

        long result = multi(6);
        System.out.println(result);

    }


    /*
          求阶乘
     */
    public static long multi(int n) {

        // 出口条件
        if (n == 1) {
            return 1;
        }

        return multi(n - 1) * n;
    }
}
